package com.elitel.common.messageQueue;


import com.alibaba.fastjson.JSON;
import com.elitel.base.variable.RabbitMQRoutingKey;
import com.elitel.frame.main.entity.state.TimePushActivemq;
import com.elitel.frame.main.entity.vo.ServerStatistics;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQHelper{

    @Autowired
    private RabbitTemplate rabbitTemplate;

	@Autowired
	private TimePushActivemq timePushActivemq;

	public void recordTimeConsumeIfNecessary(ServerStatistics server){
		if(server == null)
			return;

		// here is shutdown rabbitMQ function
		if(true)
			return;

		server.computeConsumeTime();

		if(timePushActivemq.isOpenPushSwitch() && server.getServerTime() >= timePushActivemq.getTimeInterval()) {
			rabbitTemplate.convertAndSend(RabbitMQRoutingKey.topicDestination, RabbitMQRoutingKey.serverTimeDestination, JSON.toJSONString(server));
		}
	}

}
